<template>
    <div class="container">
        <headerView class="header" :headerTitle="headerTitle" />
        <div class="container-content">
            <div class="content">
                <div class="content-item">
                    <div class="item-row-avatars">
                        <div>头像</div>
                        <div class="avatars"><img :src="headImag" alt="" @click.prevent="avatarsClick(headImag)"></div>
                    </div>
                    <div class="item-row" v-for="(item, index) in userTab" :key="index">
                        <div>{{ item.rowName }}</div>
                        <div>{{ item.rowValue }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup name="UserDetail">
import { ref, onMounted } from 'vue';
import service from '@/utils/request';
import { useRoute, useRouter } from 'vue-router';
import headerView from '@/components/Header/backHeader.vue';
const route = useRoute();
const router = useRouter();
const userId = ref(route.params.id);
const headerTitle = ref({ title: '个人信息' });
const headImag = ref('');
const userTab = ref([]);
const inteTable = () => {
    service({
        url: 'api/Users/' + userId.value,
        method: 'get',
    }).then((res) => {
        if (res != undefined) {
            headImag.value = res.data.headImag;
            userTab.value.push({ rowName: '用户ID', rowValue: res.data.id });
            userTab.value.push({ rowName: '用户名', rowValue: res.data.userName });
            userTab.value.push({ rowName: '电话', rowValue: res.data.phone });
            userTab.value.push({ rowName: '角色', rowValue: res.data.role });
            userTab.value.push({ rowName: '状态', rowValue: res.data.state == 0 ? '正常' : '禁用' });
        }
    });
};
const avatarsClick = (src) => {
    window.sessionStorage.setItem('headImag', src);
    router.push('/User/UserDetail/Avatars');
};
onMounted(() => {
    inteTable();
});
</script>
<style scoped>
.container {
    width: 100vw;
    height: 100%;
    background-color: #fff;
}

.header {
    width: 100%;
    height: 60px;
    background-color: #f5f5f5;
    box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
}

.container-content {
    width: 100%;
    height: calc(100vh - 55px);
    margin-top: 55px;
}

.content {
    width: 90%;
    margin: 0 auto;
}

.content-item {
    width: 100%;
    padding-top: 20px;
}

.item-row-avatars,
.item-row {
    margin-bottom: 10px;
    width: 100%;
    height: 60px;
    line-height: 60px;
    color: #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #cacaca;
}

.item-row {
    height: 35px;
    line-height: 35px;
}

.avatars {
    width: 50px;
    height: 50px;
}

.avatars img {
    width: 100%;
    height: 100%;
    border-radius: 5px;
}
</style>